package com.green.service.remote.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.green.model.manage.Area;
import com.green.service.manage.AreaService;
import com.green.service.remote.AreaRemoteService;
import com.green.service.remote.model.Result;

@Component
public class AreaRemoteServiceImpl implements AreaRemoteService {
	
	@Resource
	private AreaService areaService;

	@Override
	public Result<List<String>> getCitys() {
		Result<List<String>> result = new Result<List<String>>();
		result.setSuccess(true);
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("level", 2);
		List<Area> areaList = areaService.getAreaList(params);
		if (areaList != null && areaList.size() > 0) {
			List<String> citys = new ArrayList<String>(areaList.size());
			for (Area area : areaList) {
				citys.add(area.getName());
			}
			result.setData(citys);
		}
		return result;
	}
	
	@Override
	public Result<List<Area>> getAreaByCity(String city) {
		Result<List<Area>> result = new Result<List<Area>>();
		result.setSuccess(true);
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("parentName", city);
		params.put("level", 3);
		List<Area> areaList = areaService.getAreaList(params);
		if (areaList != null && areaList.size() > 0) {
			List<Area> citys = new ArrayList<Area>(areaList.size());
			for (Area area : areaList) {
				citys.add(area);
			}
			result.setData(citys);
		}
		return result;
	}

	@Override
	public Result<List<Area>> getModuleByArea(String areaId) {
		Result<List<Area>> result = new Result<List<Area>>();
		result.setSuccess(true);
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("parentId", areaId);
		params.put("level", 5);
		List<Area> areaList = areaService.getAreaList(params);
		if (areaList != null && areaList.size() > 0) {
			List<Area> citys = new ArrayList<Area>(areaList.size());
			for (Area area : areaList) {
				citys.add(area);
			}
			result.setData(citys);
		}
		return result;
	}
}
